#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include <QFileDialog>
#include <QDir>
#include <QDebug>
#include "convertor.h"
#include "mytest.h"
#include <QMap>
#include <QVector>
#include <windows.h>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

}

MainWindow::~MainWindow()
{
    delete ui;
}




void MainWindow::on_btn_open_clicked()
{

    //QString dir = QFileDialog::getOpenFileName(this,tr("Open Directory"),QDir::currentPath());
    QString dllPath = QFileDialog::getOpenFileName(this,tr("打开dll文件"),
                                                   QCoreApplication::applicationFilePath());
    qDebug() << "dllPath:" << dllPath;

    QString platform("");
    if(ui->rb_x86->isChecked()){
        platform = ui->rb_x86->text();
    }
    if(ui->rb_x64->isChecked()){
        platform = ui->rb_x64->text();
    }
    Convertor convertor(this,dllPath,platform);
    ui->lineEdit->setText(convertor.getDllPath());
qDebug() << "baseName:" << convertor.getFileBaseName();
    if(ui->rb_pexport->isChecked()){
        convertor.pexportDef();
    }

    if(ui->rb_gendef->isChecked()){
        convertor.generateDef();
    }

    if(ui->rb_mingw_to_msvc->isChecked()){
        convertor.buildLibFile();
        bool is=QFile::copy(convertor.getDllPath(),
                              QCoreApplication::applicationDirPath()+"/out/"+convertor.getFileBaseName()+".dll");
        qDebug() << "is 1:" << is;
    }

    if(ui->rb_msvc_to_mingw->isChecked()){
        convertor.buildAFile();
        bool is=QFile::copy(convertor.getDllPath(),
                              QCoreApplication::applicationDirPath()+"/out/"+convertor.getFileBaseName()+".dll");
        qDebug() << "is 2:" << is;
    }


    //        if(ui->rb_pexport->isChecked()){
    //            if(ui->rb_mingw_to_msvc->isChecked()){
    //                qDebug() << "stdcall mingw_to_msvc";
    //                auto localCurrentPath = QCoreApplication::applicationDirPath();
    //                QString pexportExePath = localCurrentPath+ "/bin/pexports.exe";
    //                QString libExePath = localCurrentPath+ "/bin/lib.exe";
    //                QString defPath = localCurrentPath+ "/out/"+ fileName+".def";
    //                QString libPath = localCurrentPath+ "/out/"+ fileName+".lib";
    //                QString defCmd = pexportExePath + " " + dllFileInfo.absoluteFilePath() +" -o > " + defPath;
    //                QString libCmd = libExePath + " " + "/out:"+ libPath +" /MACHINE:IX64 /DEF:" + defPath;
    //                qDebug() << "defCmd:" << defCmd;
    //                qDebug() << "libCmd:" << libCmd;
    //                //CmdUtil::exec(defCmd);
    //                //CmdUtil::exec(libCmd);
    //            }
    //            if(ui->rb_msvc_to_mingw->isChecked()){
    //                qDebug() << "stdcall msvc_to_mingw";
    //            }
    //        }

    //        if(ui->rb_cdecl->isChecked()){
    //            if(ui->rb_mingw_to_msvc->isChecked()){
    //                qDebug() << "cdecl mingw_to_msvc";
    //            }
    //            if(ui->rb_msvc_to_mingw->isChecked()){
    //                qDebug() << "cdecl msvc_to_mingw";
    //            }
    //        }


}

